<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<%@ include file="/common/login-info.jsp"%>

<html>
	<head>
		<title>发布业务流程</title>
		<%@ include file="/common/meta.jsp"%>
		<%@ include file="/common/jquery-ui-inc.jsp"%>
		<script>
			$(function() {
				$("#uploadForm").form({
				onSubmit:function(){
		    		if($("#upload").val()==""){
		    			$.messager.alert('提示','请选择需要上传的流程文件','warning');
		    			return false;
		    		}
		    		
		    		if($("#imgUpload").val()==""){
		    			$.messager.alert('提示','请选择需要上传的流程图片','warning');
		    			return false;
		    		}
		    		
		    		if(!checkFiles($("#upload").val(),'xml')){
		    			
		    			$.messager.alert('提示','流程定义文件格式有误','warning');
		    			return false;
		    		}
		    		
		    		if(!checkFiles($("#imgUpload").val(),'pic')){
		    			$.messager.alert('提示','流程图文件格式有误','warning');
		    			return false;
		    		}
		    				    		
		    		if($("#sysEname").val()==""){
		    			$.messager.alert('提示','请选择系统','warning');
		    			return false;
		    		}
		    		
		    		if("operator" == "${operType}"){
			    		if( $("[name='orgId']:input").val()==""){
			    			$.messager.alert('提示','请选择机构','warning');
			    			return false;
			    		}else if($("[name='orgId']:input").val()==null||typeof($("[name='orgId']:input").val())== "undefined"){
			    		    $.messager.alert('提示','机构选项异常','warning');
			    		    return false;
			    		}
		    		}else{
		    		  $("#orgId").val('<%=loginUser.getOrgId()%>');
		    		  $("#orgCname").val('<%=loginUser.getOrgCname()%>');
		    		}	
		    	   return true;
		   		 },
					url:"${ctx}/flow/core/flow-deploy!upload.action",
					success:function(data){
						var d = $.parseJSON(data);
						$.messager.alert("提示",d.msg);
						if(d.flag == 'T'){
							parent.closeBusProcessWin();
							var sysEname=$("#sysEname").val();
							var deployId=d.deployId;
							var ttt = "uploadFileName="+d.uploadFileName+"&imgUploadFileName="+d.imgUploadFileName+"&sysEname="+sysEname+"&deployId="+deployId+"&operType=${operType}"+"&orgId="+$("[name='orgId']:input").val();
							parent.location.href='${ctx}/flow/core/flow-deploy!design.action?' + ttt;
						}
						
					}
				});
				initOrgTree();
			});
			
		function initOrgTree(){
		 		 $('#orgTree').combotree({//初始化机构树
		 		 //获取数据URL
				   url:'${ctx}/flow/core/flow-deploy!orgTreeJson.action',
				   valueField:'id',
				   textField:'text',
				   panelHeight:'auto',
				   onSelect:function(node){
				    var t = $('#orgTree').combotree('tree');//得到树对象  
		     		var n = t.tree('getSelected'); // 得到选择的节点  
				    if(null != n){
				        $('#orgCname').val(n.text);  //清除选中  
				     }
				   } 
				 });
			}
			
		function next(){
			parent.parent.addTab2("设置流程",'${ctx}/flow/core/flow-deploy.action?processInsId=leaveMng-countor.40008')
		}
			
			
		function checkFiles(str,file){
		   var strRegex=null;
		   if("pic"==file){//对图片格式的验证
		   	 strRegex = "(.jpg|.png|.gif)$"; 
		   }else if("xml"==file){
		     strRegex = "(.xml)$"; 
		   }
   		   
	       var re=new RegExp(strRegex);
	       if (re.test(str.toLowerCase())){
	           return true;
	       }
	       else{
	           return false;
	       }
   		}
		
		function sysChange(){
		  $("#sysCname").val($("#sysEname option:selected").text());
		}	
	</script>
	</head>

	<body>
			<form id="uploadForm"  name="uploadForm" action="" method="POST" enctype="multipart/form-data">
				<table class="datagrid-body">
					<tr><td colspan="2"><span style="font-weight:bold;color:red;">上传的文件</span></td></tr>
					<tr>
						<td>流程定义文件<span style="color:red;">*</span>：</td>
						<td><input name="upload" id="upload" class="easyui-validatebox" required="true" type=file size=20></td>
					</tr>
					<tr>
						<td>流程图片<span style="color:red;">*</span>：</td>
						<td><input name="imgUpload" id="imgUpload" class="easyui-validatebox" required="true" type=file size=20></td>
					</tr>
					<tr>
						<td>系统名称<span style="color:red;">*</span>：</td>
						<td>
							<select id="sysEname" name="sysEname" onchange="sysChange()">
								<option value="">-请选择-</option>
								<s:iterator value="sysList" var="y">
									<option value="${y.sysEname}">${y.sysCname}</option> 
								</s:iterator>
							
							</select>
						   <input type="hidden" id="sysCname" name="sysCname" value="" />
						</td>
					</tr>
					<%Object operType = request.getAttribute("operType");
					if(operType!=null && "operator".equals(operType)){ %>
					<tr>
						<td>机构名称<span style="color:red;">*</span>：</td>
						<td>
					<span id="orgspan">
						<input id="orgTree" name="orgId" class="easyui-combotree"  style="width:300px;" />
					</span>
						<input type="hidden" id="orgCname" name="orgCname" value=""/>
						</td>
					</tr>
					<% }else{%>
					<input type="hidden" id="orgId" name="orgId" value=""/>
					<input type="hidden" id="orgCname" name="orgCname" value=""/>
					<% }%>
					<tr>
					<table id="lockList"></table>
					<td><input type="submit" value="提交"/>
					</td>
					<td><input type="reset" value="重置"/></td>
					</tr>
				</table>
			</form>
	</body>
</html>